package com.central.apps.handler;

import com.central.app.common.util.BLuntil;
import com.central.app.service.HandlerService;
import com.central.apps.handler.base.LvBaseHandler;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class AssetHandler extends LvBaseHandler {

    @Autowired
    private HandlerService handlerService;

    @Override
    public Object operate(String app, String type, Map<String, Object> params) throws Exception {
        //归属单位弹出框
        if ("getDept".equals(type)) {
            String depttype = MapUtils.getString(params, "depttype");
            String deptcode = MapUtils.getString(params, "deptcode");

            String code = BLuntil.getParameter(params, "code");
            String fullname = BLuntil.getParameter(params, "fullname");
            String sql = "select code,fullname from sys_dept  where PCODE=left('" + deptcode + "', 6) " +
                    "  and code like '%" + code + "%' and fullname like '%" + fullname + "%' ";
            if (deptcode.substring(0, 6).equals("BL0101")) {
                sql = "select code,fullname from sys_dept  where pcode in ('BL0101','BL010101')  " +
                        "  and code like '%" + code + "%' and fullname like '%" + fullname + "%' ";
            }
            return BLuntil.toPage(params, handlerService, sql);
        }
        //获取设备部位弹出框
        if ("getPart".equals(type)) {
            //获取到deptcode
            String deptcode = MapUtils.getString(params, "deptcode");
//            String sql="SELECT DISTINCT line.inspectionassetnum,line.inspectionassetname,line.part  from  bl_inspectionline line " +
//                    "LEFT JOIN bl_inspection ins on  ins.inspectionnum=line.inspectionnum " +
//                    "LEFT JOIN sys_dept  dept  on   dept.code= ins.deptcode" +
//                    "WHERE   dept.code='"+deptcode+"'";
            handlerService.findBySql("SELECT DISTINCT line.inspectionassetnum,line.inspectionassetname,line.part  from  bl_inspectionline line " +
                    " LEFT JOIN bl_inspection ins on  ins.inspectionnum=line.inspectionnum " +
                    " LEFT JOIN sys_dept  dept  on   dept.code= ins.deptcode " +
                    " WHERE   dept.code='"+deptcode+"'");
        }
        return super.operate(app, type, params);
    }
}
